package cn.duxiaod.demo.proxy.jdkDynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DebugInvocationHandle implements InvocationHandler {

    /**
     * 代理类中的真实对象
     */
    private final Object object;

    public DebugInvocationHandle(Object object){
        this.object = object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //调用方法前操作
        System.out.println("before method " + method.getName());
        Object result = method.invoke(object,args);
        //调用方法后的操作
        System.out.println("after method " + method.getName());
        return result;
    }
}
